#!/bin/sh
# Config prior to download/install of UPEK's BioAPI-Compliant TouchChip TFM/ESS
# FingerPrint Driver
#
# (C) 2001 Eric Sharkey.
# (C) 2007 Michael R. Crusoe
# You may freely distribute this file under the terms of the GNU General
# Public License, version 2 or later

set -e

# Source debconf library.
. /usr/share/debconf/confmodule

FILE_SHA512SUM="ce2a15817908429bc4462320cfde98dbbd198928abfd34bc194e2c9a2e1dd0a4cb8de7ee709ae3a0af341c7de28e68865ceeb863fc4c5
b1f78fc588490945083"
FILE="TFMESS_BSP_LIN_1.0.zip"

NEEDUPDATE=""

FILE=/usr/lib/libtfmessbsp.so

if [ ! -f /usr/lib/${FILE} ] || [ `sha512sum /usr/lib/${FILE} | awk '{print $1}'` != ${SHA512SUM} ] ; then
	NEEDUPDATE=1
fi

if [ -n "$NEEDUPDATE" ] ; then
  db_input low touchstripdriver/dldir || true
  if [ -n "$http_proxy" ] ; then
    db_set touchstripdriver/http_proxy $http_proxy
  fi
  db_input medium touchstripdriver/http_proxy || true

  db_go
  db_get touchstripdriver/dldir
  while [ -n "$RET" ] && [ `echo $RET | tr [:upper:] [:lower:] ` != "none" ] ; do
    BADDIR=""
    if [ ! -f ${RET}/${FILE} ] || [ `sha512sum ${RET}/${FILE} | awk '{print $1}'` = ${SHA512SUM} ] ; then
	BADDIR=1
    fi
    if [ -n "$BADDIR" ] ; then
        db_fset touchstripdriver/baddldir seen false
        db_fset touchstripdriver/dldir seen false
        db_input critical touchstripdriver/baddldir || true
        db_input critical touchstripdriver/dldir || true
        db_go
        db_get touchstripdriver/dldir
    else
        break
    fi
  done

fi

